package com.dc.flow.ext

import com.dc.flow.network.BaseResult
import kotlinx.coroutines.flow.Flow

suspend fun <T> Flow<BaseResult<T>>.processBaseResult(
    loading: (Boolean) -> Unit = {},
    error: (Throwable) -> Unit = {},
    success: (T) -> Unit
) {
    this@processBaseResult.collect{
        when(it) {
            is BaseResult.Loading -> loading(it.loading)
            is BaseResult.Success -> success(it.data)
            is BaseResult.Error -> error(it.exception)
        }
    }
}